package com.example.redis.pubsub;


public class TestRedisQuene {
    public static byte[] redisKey = "key".getBytes();
    static{
        //init();
    }
    public static void main(String[] args) {
        System.out.println(System.getProperty("user.dir"));

        init();
        pop();
    }

    private static void pop() {
        //System.out.println( JedisUtil.lpopList(redisKey));
        byte[] bytes = JedisUtil.rpop(redisKey);
        Message msg = null;
        try {
            msg = (Message) ObjectUtil.bytesToObject(bytes);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if(msg != null){
            System.out.println(msg.getId()+"   "+msg.getContent());
        }
    }

    private static void init() {

        try {
            Message msg1 = new Message(1, "内容1");
            JedisUtil.lpush(redisKey, ObjectUtil.objectToBytes(msg1));
            Message msg2 = new Message(2, "内容2");
            JedisUtil.lpush(redisKey, ObjectUtil.objectToBytes(msg2));
            Message msg3 = new Message(3, "内容3");
            JedisUtil.lpush(redisKey, ObjectUtil.objectToBytes(msg3));

//            System.out.println(JedisUtil.llen(redisKey));
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}